; rst 08h, macros kld, kcall, kjp
; Loads the correct address into
; executing programs at runtime
rmacro:
	ex (sp),hl				; Save hl and get the return address
	push af					; Save af, bc, and de
	push bc
	push de
		dec hl
		ld (hl),0			; Replace rst 08h with nop
		inc hl
		inc hl
		ld c,(hl)			; Load the offset into bc
		inc hl
		ld b,(hl)
		push hl				; Save the insertion point
			ld a,(CurrentThreadID)
			call GetThreadEntry	; Get the thread entry
			inc hl			; Move to the executable address entry
			ld e,(hl)		; Load the executable address into de
			inc hl
			ld d,(hl)
			ex de,hl		; Swap the address into hl
			add hl,bc		; Add the offset to the address
			ex de,hl		; Put the address back into de
		pop hl				; Restore the insertion point
		ld (hl),d			; Store the adjusted address
		dec hl
		ld (hl),e
		dec hl				; Adjust hl to point to the return address
	pop de					; Restore af, bc, and de
	pop bc
	pop af
	ex (sp),hl				; Restore hl and put the return address on the stack
	ret
